const path = require("path");
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");

const devMode = process.env.NODE_ENV !== "production";

module.exports = {
  mode: devMode ? "development" : "production",
  entry: {
    gun: "./src/gun.js",
    user: "./src/user.js"
  },
  output: {
    path: path.join(__dirname, "build"),
    filename: devMode ? "[name].js" : "[name].[chunkhash:8].js"
  },
  externals: [nodeExternals()],
  module: {
    rules: [
      {
        enforce: "pre",
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        //use: "eslint-loader"
        use: {
          loader: "eslint-loader",
          options: {
            cache: false
            //configFile: path.join(__dirname, ".eslintrc.json")
          }
        }
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"]
          }
        }
      }
    ]
  }
};
